from LeetCoder import *


class Solution:

    def minLength(self, s: str) -> int:
        l = list(s)
        ans = []
        for c in l:
            if c == 'B' and len(ans) > 0 and ans[-1] == 'A':
                ans.pop()
            elif c == 'D' and len(ans) > 0 and ans[-1] == 'C':
                ans.pop()
            else:
                ans.append(c)
        return len(ans)


s = Solution()
print(s)
